﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;

namespace TienLen
{
    public partial class GameSelection : Form
    {
        public CGLib.IGame selectedGame;

        bool options = false;

        public GameSelection()
        {
            InitializeComponent();
            Util.LoadCursor(this, CursorType.Default);

            for (int i = 0; i < SvrFunc.Games.Count; i++)
                listGames.Items.Add(SvrFunc.Games[i].Name());

            if (listGames.Items.Count == 0)
            {
                MessageBox.Show("You have no installed games for Tien Len.", "No Games Found", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.DialogResult = DialogResult.Cancel;

                return;
            }
            else
                listGames.SelectedIndex = 0;
        }

        private void listGames_SelectedIndexChanged(object sender, EventArgs e)
        {
            info.Text = SvrFunc.Games[listGames.SelectedIndex].Description();
            picGame.Image = SvrFunc.Games[listGames.SelectedIndex].ImageOverview();

            btnOption.Enabled = SvrFunc.Games[listGames.SelectedIndex].AllowOptions();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (listGames.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a type of game to play.", "Select Game", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                selectedGame = SvrFunc.Games[listGames.SelectedIndex];
                this.DialogResult = DialogResult.OK;
            }
        }

        private void btnOption_Click(object sender, EventArgs e)
        {
            options = true;
            SvrFunc.Games[listGames.SelectedIndex].LoadOptions(null);
        }

        private void GameSelection_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (options)
            {
                e.Cancel = true;
                options = false;
            }
        }
    }
}
